<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>调用子组件的方法（或者属性）</h1>
    <p>思考：如何在父组件中调用子组件的方法或者属性？</p>
    <template id="temp1">
        <h2>
           我是子组件
        </h2>
    </template>
    <main id="app">
        <button @click="handleClick">点击我</button>
        <my-com ref="sub-com"></my-com>
    </main>
</body>
<script src="../vue.js"></script>
<script>
    new Vue({
        el: "#app",
        methods: {
            handleClick() {
               this.$refs["sub-com"].sayHello();
            }
        },
        components: {
            "my-com": {
                template: "#temp1",
                methods: {
                    sayHello() {
                        console.log("你好！我是子组件！");
                    }
                }
            },
        }
    })
</script>
</html>